package com.project.core.entity;

import com.project.core.constant.ScoreConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 接口通用返回体
 * @author mengxj
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code;

    private T data;

    private String message;

    public Result(int code, T t){
        this(code, t, ScoreConstant.OPERATOR_SUCCESS_MESSAGE);
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T t) {
        return new Result<>(ScoreConstant.OPERATOR_SUCCESS_CODE, t);
    }

    public static <T> Result<T> fail() {
        return fail(ScoreConstant.OPERATOR_ERROR_MESSAGE);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(ScoreConstant.OPERATOR_ERROR_CODE, null, message);
    }
}
